package com.service.store.impl;

import com.dao.store.CatalogDao;
import com.domain.store.Catalog;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.service.store.CatalogService;
import com.utils.MapperUtils;
import org.apache.ibatis.session.SqlSession;

import java.io.IOException;
import java.util.List;
import java.util.UUID;

public class CatalogServiceImpl implements CatalogService {
    private CatalogDao catalogDao;

    public void setCatalogDao(CatalogDao catalogDao) {
        this.catalogDao = catalogDao;
    }

    /**
     * 查询全部
     * @return
     */
    @Override
    public List<Catalog> findAll() {
        return catalogDao.findAll();
    }

    /**
     * 分页查询
     * @param page
     * @param size
     * @return
     */
    @Override
    public PageInfo findAll(int page, int size) {
        Page pages = PageHelper.startPage(page,size);
        catalogDao.findAll();
        return new PageInfo(pages);
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @Override
    public Catalog findById(String id) {
        return catalogDao.findById(id);
    }

    /**
     * 添加操作
     * @param catalog
     */
    @Override
    public void save(Catalog catalog) {
        String id = UUID.randomUUID().toString();
        catalog.setId(id);
        catalogDao.save(catalog);
    }

    /**删除操作
     * @param catalog
     */
    @Override
    public void delete(Catalog catalog) {
        catalogDao.delete(catalog);
    }

    /**
     * 修改操作
     * @param catalog
     */
    @Override
    public void update(Catalog catalog) {
        catalogDao.update(catalog);
    }
}
